<?php
$q=$_GET["q"];
$array= explode(",",$q);
$tra=$array[0];
$School_Id=$array[1];
$Access_Type=$array[2];
$Id=$Access_Type.",".$School_Id.",School_Id";
$hint="";
include_once '../Login/databaseconnection.php';
if($tra!="Select One"&&$School_Id!="")
{
$all_tea=mysql_query("SELECT * FROM teacher WHERE School_Id='$School_Id'");
if($all_tea)
{
while($rowalltea=mysql_fetch_array($all_tea))
{
if(empty($All_Teachers))
{
$All_Teachers='"'.$rowalltea['T_NIC_Number'].'"';
}
else
{
$All_Teachers=$All_Teachers.',"'.$rowalltea['T_NIC_Number'].'"';
}
}
}
$tra_id=mysql_query("SELECT * FROM training WHERE Training_Name='$tra'");
if($row=mysql_fetch_array($tra_id))
{
$train_id=$row['Training_Id'];
}
$tot_tea=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS tot_teachers FROM training_details WHERE Training_Id='$train_id' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($All_Teachers)");
if($tot_tea)
{
if($row_tea=mysql_fetch_array($tot_tea))
{
$Tra_Teachers=$row_tea['tot_teachers'];
}
}
if($Tra_Teachers=="")
{
$Tra_Teachers="0";
}
$tot_res_per=mysql_query("SELECT COUNT(DISTINCT(T_NIC_Number)) AS res_per FROM resource_team WHERE Training_Id='$train_id' GROUP BY T_NIC_Number HAVING T_NIC_Number in ($All_Teachers)");
if($tot_res_per)
{
if($row_res_per=mysql_fetch_array($tot_res_per))
{
$Res_per=$row_res_per['res_per'];
}
}
if($Res_per=="")
{
$Res_per="0";
}
$hint="<label>Total number of trained teachers:</label><input type='text' name='Tra_Teachers' value='$Tra_Teachers' readonly='readonly' onmouseover='clearpopbox()'/><br/><br/><label>Number of resource persons:</label><input type='text' name='Resource_Persons' value='$Res_per' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'<br/><br/><label>Duration </label>';
        $hint=$hint."<select name='func' id='$School_Id' onChange='getDurati(this.value,this.id)' onmouseover='clearpopbox()'>";
        $hint=$hint.'<option value="=">Equal to</option><option value=">">Greater than</option><option value=">=">Greater than or equal to</option><option value="<">Less than</option><option value="<=">Less than or equal to</option>';
        $hint=$hint.'</select>
         <label> </label>
          <div id="Durati">';
		 $hint=$hint."<select name='Duration' id='$School_Id' onChange='duration(this.value,this.id)' onmouseover='clearpopbox()'>";
		 $nothing="";
$alldura=mysql_query("SELECT * FROM training_details");
while($rowalldura=mysql_fetch_array($alldura))
{
$Dura=$rowalldura['Duration'];
$sql="SELECT * FROM training_details WHERE Duration='".$Dura."' AND Training_Id='".$train_id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($All_Teachers)";
$tot_tea=mysql_query($sql);
if($tot_tea)
{
if(mysql_num_rows($tot_tea)>0)
{
$nothing="false";
$hint=$hint.'<option value="'.$Dura.'">'.$Dura.'</option>';
if(empty($first_option))
{
$first_option=$Dura;
}
}
}
}
if($nothing!="false")
{
$hint=$hint.'<option value="">No result</option>';
}
$tot_f_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Female' OR Gender='female') AND School_Id='$School_Id'");
if($tot_f_tea)
{
while($row_fe_tea=mysql_fetch_array($tot_f_tea))
{
if(empty($Female_Teachers))
{
$Female_Teachers='"'.$row_fe_tea['T_NIC_Number'].'"';
}
else
{
$Female_Teachers=$Female_Teachers.',"'.$row_fe_tea['T_NIC_Number'].'"';
}
}
}
$tot_m_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Male' OR Gender='male') AND School_Id='$School_Id'");
if($tot_m_tea)
{
while($row_ma_tea=mysql_fetch_array($tot_m_tea))
{
if(empty($Male_Teachers))
{
$Male_Teachers='"'.$row_ma_tea['T_NIC_Number'].'"';
}
else
{
$Male_Teachers=$Male_Teachers.',"'.$row_ma_tea['T_NIC_Number'].'"';
}
}
}
if($first_option!="")
{
$fir_val_male=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS males FROM training_details WHERE Duration".$sym."'".$first_option."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Male_Teachers)");
if($fir_val_male)
{
if($row_fir_mval=mysql_fetch_array($fir_val_male))
{
$Tra_Male_Teachers=$row_fir_mval['males'];
}
}

$fir_val_female=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS females FROM training_details WHERE Duration".$sym."'".$first_option."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Female_Teachers)");
if($fir_val_female)
{
if($row_fir_fval=mysql_fetch_array($fir_val_female))
{
$Tra_Female_Teachers=$row_fir_fval['females'];
}
}
}
$hint=$hint.'</select></form><label> :</label><div id="byduration"><table height="105" class="imgholder1">  
              <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <th> </th>
         <td></td>
         </tr>
		 <tr>
		 <th><label>Number of male teachers:</label>
         </th>
         <td>';
		 if($Tra_Male_Teachers=="")
		 {
		 $Tra_Male_Teachers="0";
		 }
		 if($Tra_Female_Teachers=="")
		 {
		 $Tra_Female_Teachers="0";
		 }
if($Tra_Male_Teachers!="0")
{
$hint=$hint."<input type='text' name='Tra_Male_Teachers' value='$Tra_Male_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Tra_Male_Teachers' value='$Tra_Male_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of female teachers:</label>
         </th>
         <td>';
if($Tra_Female_Teachers!="0")
{
$hint=$hint."<input type='text' name='Tra_Female_Teachers' value='$Tra_Female_Teachers' readonly='readonly' id='$Id' onmouseover='getdetails_popup(this.name,this.id)'/>";
}
else
{
$hint=$hint."<input type='text' name='Tra_Female_Teachers' value='$Tra_Female_Teachers' readonly='readonly' onmouseover='clearpopbox()'/>";
}
$hint=$hint.'</td></tr> 
           </table></div></div>';
}
if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
$response=$response."<label>Total number of trained teachers:</label><input type='text' name='Tra_Teachers' readonly='readonly'/><br/><br/><label>Number of resource persons:</label><input type='text' name='Resource_Persons' readonly='readonly'/>";
$response=$response.'<br/><br/><label>Duration </label>';
        $response=$response."<select name='func' id='' onChange='getDurati(this.value,this.id)'>";
        $response=$response.'<option value="=">Equal to</option><option value=">">Greater than</option><option value=">=">Greater than or equal to</option><option value="<">Less than</option><option value="<=">Less than or equal to</option>';
        $response=$response.'</select>
         <label> </label>
          <div id="Durati">';
		 $response=$response."<select name='Duration' id='' onChange='duration(this.value,this.id)'>";
		 $nothing="";
$alldura=mysql_query("SELECT * FROM training_details");
while($rowalldura=mysql_fetch_array($alldura))
{
$Dura=$rowalldura['Duration'];
$sql="SELECT * FROM training_details WHERE Duration='".$Dura."' AND Training_Id='".$train_id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($All_Teachers)";
$tot_tea=mysql_query($sql);
if($tot_tea)
{
if(mysql_num_rows($tot_tea)>0)
{
$nothing="false";
$response=$response.'<option value="'.$Dura.'">'.$Dura.'</option>';
if(empty($first_option))
{
$first_option=$Dura;
}
}
}
}
if($nothing!="false")
{
$response=$response.'<option value="">No result</option>';
}
$tot_f_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Female' OR Gender='female') AND School_Id='$School_Id'");
if($tot_f_tea)
{
while($row_fe_tea=mysql_fetch_array($tot_f_tea))
{
if(empty($Female_Teachers))
{
$Female_Teachers='"'.$row_fe_tea['T_NIC_Number'].'"';
}
else
{
$Female_Teachers=$Female_Teachers.',"'.$row_fe_tea['T_NIC_Number'].'"';
}
}
}
$tot_m_tea=mysql_query("SELECT * FROM teacher WHERE (Gender='Male' OR Gender='male') AND School_Id='$School_Id'");
if($tot_m_tea)
{
while($row_ma_tea=mysql_fetch_array($tot_m_tea))
{
if(empty($Male_Teachers))
{
$Male_Teachers='"'.$row_ma_tea['T_NIC_Number'].'"';
}
else
{
$Male_Teachers=$Male_Teachers.',"'.$row_ma_tea['T_NIC_Number'].'"';
}
}
}
if($first_option!="")
{
$fir_val_male=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS males FROM training_details WHERE Duration".$sym."'".$first_option."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Male_Teachers)");
if($fir_val_male)
{
if($row_fir_mval=mysql_fetch_array($fir_val_male))
{
$Tra_Male_Teachers=$row_fir_mval['males'];
}
}

$fir_val_female=mysql_query("SELECT COUNT(DISTINCT(Teacher_NIC)) AS females FROM training_details WHERE Duration".$sym."'".$first_option."' AND Training_Id='".$Training_Id."' GROUP BY Teacher_NIC HAVING Teacher_NIC in ($Female_Teachers)");
if($fir_val_female)
{
if($row_fir_fval=mysql_fetch_array($fir_val_female))
{
$Tra_Female_Teachers=$row_fir_fval['females'];
}
}
}
$response=$response.'</select></form><label> :</label><div id="byduration"><table height="105" class="imgholder1">  
              <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <th> </th>
         <td></td>
         </tr>
		 <tr>
		 <th><label>Number of male teachers:</label>
         </th>
         <td>';
		          $response=$response."<input type='text' name='Tra_Male_Teachers' readonly='readonly'/>";
$response=$response.'</td>
         </tr>   
       <tr>
        <th>        
         <label>Number of female teachers:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Tra_Female_Teachers' readonly='readonly'/>";
$response=$response.'</td></tr> 
           </table></div></div>';
}
else
{
$response=$hint;
}
echo $response;
?>